{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "76910974",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0a36f3ad",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['E:\\\\jupyter',\n",
       " 'D:\\\\anaconda3\\\\python311.zip',\n",
       " 'D:\\\\anaconda3\\\\DLLs',\n",
       " 'D:\\\\anaconda3\\\\Lib',\n",
       " 'D:\\\\anaconda3',\n",
       " '',\n",
       " \"C:\\\\Users\\\\z'y'y\\\\AppData\\\\Roaming\\\\Python\\\\Python311\\\\site-packages\",\n",
       " 'D:\\\\anaconda3\\\\Lib\\\\site-packages',\n",
       " 'D:\\\\anaconda3\\\\Lib\\\\site-packages\\\\win32',\n",
       " 'D:\\\\anaconda3\\\\Lib\\\\site-packages\\\\win32\\\\lib',\n",
       " 'D:\\\\anaconda3\\\\Lib\\\\site-packages\\\\Pythonwin']"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sys.path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "82fb3b07",
   "metadata": {},
   "outputs": [],
   "source": [
    "sys.path.append(\"E:\\\\packaging_tutorial\\\\src\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "11aad4b2-9d7a-4475-beac-81f53837fd30",
   "metadata": {},
   "outputs": [],
   "source": [
    "sys.path.insert(0,'E:\\\\sympy')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "4341c892",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['E:\\\\sympy',\n",
       " 'E:\\\\jupyter',\n",
       " 'D:\\\\anaconda3\\\\python311.zip',\n",
       " 'D:\\\\anaconda3\\\\DLLs',\n",
       " 'D:\\\\anaconda3\\\\Lib',\n",
       " 'D:\\\\anaconda3',\n",
       " '',\n",
       " \"C:\\\\Users\\\\z'y'y\\\\AppData\\\\Roaming\\\\Python\\\\Python311\\\\site-packages\",\n",
       " 'D:\\\\anaconda3\\\\Lib\\\\site-packages',\n",
       " 'D:\\\\anaconda3\\\\Lib\\\\site-packages\\\\win32',\n",
       " 'D:\\\\anaconda3\\\\Lib\\\\site-packages\\\\win32\\\\lib',\n",
       " 'D:\\\\anaconda3\\\\Lib\\\\site-packages\\\\Pythonwin',\n",
       " 'E:\\\\packaging_tutorial\\\\src']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sys.path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "53877be7",
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "65487ae3",
   "metadata": {},
   "outputs": [],
   "source": [
    "%autoreload 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "063c3926",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy.abc import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "7a50e3d2",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "b91e5f52",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy.calculus.util import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "7fa9fdc8-55d6-4329-a856-7ac130897301",
   "metadata": {},
   "outputs": [],
   "source": [
    "%aimport sympy.geometry\n",
    "from sympy.geometry import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "3f066870",
   "metadata": {},
   "outputs": [],
   "source": [
    "%aimport basic_package.utils\n",
    "from basic_package.utils import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "f6385fd8-a961-4d0a-9a39-5081f16c7384",
   "metadata": {},
   "outputs": [],
   "source": [
    "%aimport excel_function_package.chi_square_test\n",
    "from excel_function_package.chi_square_test import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "3f4576ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "%aimport function_calculator_package.extreme_points\n",
    "from function_calculator_package.extreme_points import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "fd0d78e7",
   "metadata": {},
   "outputs": [],
   "source": [
    "%aimport quadratic_function.utils\n",
    "from quadratic_function.utils import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "80189aaa",
   "metadata": {},
   "outputs": [],
   "source": [
    "%aimport quadratic_function.quadraticfunction\n",
    "from quadratic_function.quadraticfunction import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "402baddc",
   "metadata": {},
   "outputs": [],
   "source": [
    "x=symbols(\"x\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "751463b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle x = 1 \\Rightarrow x^{2} = 1$"
      ],
      "text/plain": [
       "Implies(Eq(x, 1), Eq(x**2, 1))"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Eq(x,1) >> Eq(x**2,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "6a6f9a1d",
   "metadata": {},
   "outputs": [],
   "source": [
    "f=Function(\"f\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "cce78de3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle f{\\left(f{\\left(x \\right)} \\right)}$"
      ],
      "text/plain": [
       "f(f(x))"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f(f(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "7f77654a",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function satisfiable in module sympy.logic.inference:\n",
      "\n",
      "satisfiable(expr, algorithm=None, all_models=False, minimal=False)\n",
      "    Check satisfiability of a propositional sentence.\n",
      "    Returns a model when it succeeds.\n",
      "    Returns {true: true} for trivially true expressions.\n",
      "    \n",
      "    On setting all_models to True, if given expr is satisfiable then\n",
      "    returns a generator of models. However, if expr is unsatisfiable\n",
      "    then returns a generator containing the single element False.\n",
      "    \n",
      "    Examples\n",
      "    ========\n",
      "    \n",
      "    >>> from sympy.abc import A, B\n",
      "    >>> from sympy.logic.inference import satisfiable\n",
      "    >>> satisfiable(A & ~B)\n",
      "    {A: True, B: False}\n",
      "    >>> satisfiable(A & ~A)\n",
      "    False\n",
      "    >>> satisfiable(True)\n",
      "    {True: True}\n",
      "    >>> next(satisfiable(A & ~A, all_models=True))\n",
      "    False\n",
      "    >>> models = satisfiable((A >> B) & B, all_models=True)\n",
      "    >>> next(models)\n",
      "    {A: False, B: True}\n",
      "    >>> next(models)\n",
      "    {A: True, B: True}\n",
      "    >>> def use_models(models):\n",
      "    ...     for model in models:\n",
      "    ...         if model:\n",
      "    ...             # Do something with the model.\n",
      "    ...             print(model)\n",
      "    ...         else:\n",
      "    ...             # Given expr is unsatisfiable.\n",
      "    ...             print(\"UNSAT\")\n",
      "    >>> use_models(satisfiable(A >> ~A, all_models=True))\n",
      "    {A: False}\n",
      "    >>> use_models(satisfiable(A ^ A, all_models=True))\n",
      "    UNSAT\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(satisfiable)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "5378b257",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{A: False, B: True, C: False}\n",
      "{A: False, B: False, C: True}\n",
      "{A: True, B: True, C: False}\n"
     ]
    }
   ],
   "source": [
    "A,B,C= symbols('A,B,C')\n",
    "expr1_1 = (A >> B)\n",
    "expr1_2 = (B >> ~C)\n",
    "expr1_3 = ~C >>(A | B)\n",
    "expr1 = expr1_1 & expr1_2 & expr1_3\n",
    "models = satisfiable(expr1,all_models=True)\n",
    "for i in models:\n",
    "    print(i)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "92f8f5fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy.abc import x,y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "797dbd29",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr = (1-y)/(1+y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "f8121546",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle y$"
      ],
      "text/plain": [
       "y"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "simplify(expr.subs(y,expr))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "a03b9b41",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr = ((cos(x)**2+sin(x)**2)-sin(x)**6-cos(x)**6)/((cos(x)**2+sin(x)**2)-sin(x)**4-cos(x)**4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "674f488c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{- \\sin^{6}{\\left(x \\right)} + \\sin^{2}{\\left(x \\right)} - \\cos^{6}{\\left(x \\right)} + \\cos^{2}{\\left(x \\right)}}{- \\sin^{4}{\\left(x \\right)} + \\sin^{2}{\\left(x \\right)} - \\cos^{4}{\\left(x \\right)} + \\cos^{2}{\\left(x \\right)}}$"
      ],
      "text/plain": [
       "(-sin(x)**6 + sin(x)**2 - cos(x)**6 + cos(x)**2)/(-sin(x)**4 + sin(x)**2 - cos(x)**4 + cos(x)**2)"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "0cbe843e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{\\left(\\sin^{2}{\\left(x \\right)} + \\cos^{2}{\\left(x \\right)}\\right) \\left(\\sin^{4}{\\left(x \\right)} - \\sin^{2}{\\left(x \\right)} \\cos^{2}{\\left(x \\right)} + \\cos^{4}{\\left(x \\right)} - 1\\right)}{\\sin^{4}{\\left(x \\right)} - \\sin^{2}{\\left(x \\right)} + \\cos^{4}{\\left(x \\right)} - \\cos^{2}{\\left(x \\right)}}$"
      ],
      "text/plain": [
       "(sin(x)**2 + cos(x)**2)*(sin(x)**4 - sin(x)**2*cos(x)**2 + cos(x)**4 - 1)/(sin(x)**4 - sin(x)**2 + cos(x)**4 - cos(x)**2)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "factor(expr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e3aa5f87",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "dd225e57",
   "metadata": {},
   "source": [
    "## 湖北省新洲一中T8联盟卷"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "8f3f6267",
   "metadata": {},
   "outputs": [],
   "source": [
    "M=solveset(log(x,2)<2,x,Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "1c3cada7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\left\\{x\\; \\middle|\\; x \\in \\mathbb{R} \\wedge \\frac{\\log{\\left(x \\right)}}{\\log{\\left(2 \\right)}} < 2 \\right\\}$"
      ],
      "text/plain": [
       "ConditionSet(x, log(x)/log(2) < 2, Reals)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "5dd180e5",
   "metadata": {},
   "outputs": [],
   "source": [
    "M=Interval.open(0,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "2702f7f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\left(0, 4\\right)$"
      ],
      "text/plain": [
       "Interval.open(0, 4)"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "88a13f2d",
   "metadata": {},
   "outputs": [],
   "source": [
    "N=solveset((x-6)/(2-x)<=0,x,Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "fd4dab94",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\left(-\\infty, 2\\right) \\cup \\left[6, \\infty\\right)$"
      ],
      "text/plain": [
       "Union(Interval.open(-oo, 2), Interval(6, oo))"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "N"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "5d220743",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\left(-\\infty, 4\\right) \\cup \\left[6, \\infty\\right)$"
      ],
      "text/plain": [
       "Union(Interval.open(-oo, 4), Interval(6, oo))"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "M+N"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "10608f21",
   "metadata": {},
   "outputs": [],
   "source": [
    "z=-1+sqrt(3)*I"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "78be15c8",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "answer=z/conjugate(z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "767bf124",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{-1 + \\sqrt{3} i}{-1 - \\sqrt{3} i}$"
      ],
      "text/plain": [
       "(-1 + sqrt(3)*I)/(-1 - sqrt(3)*I)"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "answer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "b3052bf4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle - \\frac{1}{2}$"
      ],
      "text/plain": [
       "-1/2"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "re(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "81ada438",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle - \\frac{\\sqrt{3}}{2}$"
      ],
      "text/plain": [
       "-sqrt(3)/2"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "im(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "2bc87225",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function sequence in module sympy.series.sequences:\n",
      "\n",
      "sequence(seq, limits=None)\n",
      "    Returns appropriate sequence object.\n",
      "    \n",
      "    Explanation\n",
      "    ===========\n",
      "    \n",
      "    If ``seq`` is a SymPy sequence, returns :class:`SeqPer` object\n",
      "    otherwise returns :class:`SeqFormula` object.\n",
      "    \n",
      "    Examples\n",
      "    ========\n",
      "    \n",
      "    >>> from sympy import sequence\n",
      "    >>> from sympy.abc import n\n",
      "    >>> sequence(n**2, (n, 0, 5))\n",
      "    SeqFormula(n**2, (n, 0, 5))\n",
      "    >>> sequence((1, 2, 3), (n, 0, 5))\n",
      "    SeqPer((1, 2, 3), (n, 0, 5))\n",
      "    \n",
      "    See Also\n",
      "    ========\n",
      "    \n",
      "    sympy.series.sequences.SeqPer\n",
      "    sympy.series.sequences.SeqFormula\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(sequence)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "0742fcbc",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr = 2*sin(x)-exp(x)+exp(-x)-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "c45f9c1a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle - e^{x} + 2 \\sin{\\left(x \\right)} - 1 + e^{- x}$"
      ],
      "text/plain": [
       "-exp(x) + 2*sin(x) - 1 + exp(-x)"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "c745437c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\left(1, \\infty\\right)$"
      ],
      "text/plain": [
       "Interval.open(1, oo)"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "solveset(x<3*x-2,x,Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "ee5cb84b",
   "metadata": {},
   "outputs": [],
   "source": [
    "t=symbols(\"t\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "da38afaa",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=cos(11*pi/6-x)/sin(2*x+5*pi/6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "09e161cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{\\cos{\\left(x + \\frac{\\pi}{6} \\right)}}{\\cos{\\left(2 x + \\frac{\\pi}{3} \\right)}}$"
      ],
      "text/plain": [
       "cos(x + pi/6)/cos(2*x + pi/3)"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "301f7b46",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\cos{\\left(x + \\frac{\\pi}{6} \\right)}$"
      ],
      "text/plain": [
       "cos(x + pi/6)"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sin(pi/3-x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "367b5725",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{20}{7}$"
      ],
      "text/plain": [
       "20/7"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand_trig(expr.subs(x,t-pi/6)).subs(cos(t),S(4)/5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "5640fe72",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\log{\\left(x \\right)} - \\frac{2 x - 2}{x + 1}$"
      ],
      "text/plain": [
       "log(x) - (2*x - 2)/(x + 1)"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expr=ln(x)-2*(x-1)/(x+1)\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "7e7105bc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{\\left(x - 1\\right)^{2}}{x \\left(x + 1\\right)^{2}}$"
      ],
      "text/plain": [
       "(x - 1)**2/(x*(x + 1)**2)"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "factor(diff(expr,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "dfab63c9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}-1\\\\0\\\\\\frac{2}{3}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "Matrix([\n",
       "[ -1],\n",
       "[  0],\n",
       "[2/3]])"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A=Matrix([-1,0,2/S(3)])\n",
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "34d533a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}0\\\\-1\\\\1\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "Matrix([\n",
       "[ 0],\n",
       "[-1],\n",
       "[ 1]])"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "B=Matrix([0,-1,1])\n",
    "B"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "e634a897",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}\\frac{2}{3}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "Matrix([[2/3]])"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A.T*B"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "3760b5f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{13}{9}$"
      ],
      "text/plain": [
       "13/9"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "det(A.T*A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "cb90f26d",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy.stats import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "c9d08b47",
   "metadata": {},
   "outputs": [],
   "source": [
    "X=Binomial(\"X\",8,S(1)/2,1,-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "e013512b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{-8: 1/256,\n",
       " -6: 1/32,\n",
       " -4: 7/64,\n",
       " -2: 7/32,\n",
       " 0: 35/128,\n",
       " 2: 7/32,\n",
       " 4: 7/64,\n",
       " 6: 1/32,\n",
       " 8: 1/256}"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "density(X).dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "e0996af6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\frac{91}{128}$"
      ],
      "text/plain": [
       "91/128"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "P(abs(X)<=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "ef5c5fd2",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_list=[13,27,24,12,14,30,15,17,19,23]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "6708cf64",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_list.sort()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "17f9a57d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[12, 13, 14, 15, 17, 19, 23, 24, 27, 30]"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "c8233fdd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle - 24 x^{\\frac{23}{6}} - 13608 x^{\\frac{19}{6}} - 17496 x^{\\frac{17}{6}} + 252 x^{\\frac{11}{3}} + 5670 x^{\\frac{10}{3}} + 6561 x^{\\frac{8}{3}} - 1512 x^{\\frac{7}{2}} + x^{4} + 20412 x^{3}$"
      ],
      "text/plain": [
       "-24*x**(23/6) - 13608*x**(19/6) - 17496*x**(17/6) + 252*x**(11/3) + 5670*x**(10/3) + 6561*x**(8/3) - 1512*x**(7/2) + x**4 + 20412*x**3"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "expand((-sqrt(x)+3*pow(x,1/S(3)))**8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "1c292191",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy.abc import a,b,c,y,x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "35a4d00c",
   "metadata": {},
   "outputs": [],
   "source": [
    "A=Matrix([a,b])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "5cded277",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\left[\\begin{matrix}a^{2} & a b\\\\a b & b^{2}\\end{matrix}\\right]$"
      ],
      "text/plain": [
       "Matrix([\n",
       "[a**2,  a*b],\n",
       "[ a*b, b**2]])"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A*A.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "b915811e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\emptyset$"
      ],
      "text/plain": [
       "EmptySet"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "linsolve((A*A.T,Matrix([a**2/2,b**2/2])),[x,y])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "38267114",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\left\\{\\left( \\frac{- a + b t}{2 a t^{2} - 2 a}, \\  \\frac{a t - b}{2 b t^{2} - 2 b}\\right)\\right\\}$"
      ],
      "text/plain": [
       "{((-a + b*t)/(2*a*t**2 - 2*a), (a*t - b)/(2*b*t**2 - 2*b))}"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "linsolve((Matrix([[a**2,a*b*t],[a*b*t,b**2]]),Matrix([a**2/2,b**2/2])),[x,y])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "b69a2419",
   "metadata": {},
   "outputs": [],
   "source": [
    "para=Parabola(Point(-2,0),Line(x-2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "29d7b7cb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle - 8 x - y^{2}$"
      ],
      "text/plain": [
       "-8*x - y**2"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "para.equation()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "754c9d3a",
   "metadata": {},
   "outputs": [],
   "source": [
    "A=Point(0,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "5a1d13d2",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "distance between Point and <class 'sympy.geometry.parabola.Parabola'> is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[72], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m A\u001b[38;5;241m.\u001b[39mdistance(para)\n",
      "File \u001b[1;32mE:\\sympy\\sympy\\geometry\\point.py:436\u001b[0m, in \u001b[0;36mPoint.distance\u001b[1;34m(self, other)\u001b[0m\n\u001b[0;32m    434\u001b[0m distance \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mgetattr\u001b[39m(other, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdistance\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m)\n\u001b[0;32m    435\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m distance \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m--> 436\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdistance between Point and \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m is not defined\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m%\u001b[39m \u001b[38;5;28mtype\u001b[39m(other))\n\u001b[0;32m    437\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m distance(\u001b[38;5;28mself\u001b[39m)\n",
      "\u001b[1;31mTypeError\u001b[0m: distance between Point and <class 'sympy.geometry.parabola.Parabola'> is not defined"
     ]
    }
   ],
   "source": [
    "A.distance(para)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "95853585",
   "metadata": {},
   "outputs": [],
   "source": [
    "f=Function(\"f\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "89323ba0",
   "metadata": {},
   "outputs": [],
   "source": [
    "n = symbols(\"n\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "677b2393",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr = n*(f(n+1)-f(n)-n-1)-f(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c3d54bc2",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0406716a",
   "metadata": {},
   "outputs": [],
   "source": [
    "rsolve(expr,f(n),{f(1):1})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a038999d",
   "metadata": {},
   "outputs": [],
   "source": [
    "se=_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "87d6f568",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(se-se.subs(n,n-1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0a5a68a3",
   "metadata": {},
   "outputs": [],
   "source": [
    "ae=_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "374ef31f",
   "metadata": {},
   "outputs": [],
   "source": [
    "ae"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8de650be",
   "metadata": {},
   "outputs": [],
   "source": [
    "be=n*ae.subs(n,n+2)/((n+1)*3**(n+1)*n**2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fa686c4b",
   "metadata": {},
   "outputs": [],
   "source": [
    "be"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "790e6d4b",
   "metadata": {},
   "outputs": [],
   "source": [
    "m=symbols(\"m\",nature =True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8073c54c",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(summation(be,(n,1,m)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e9d69223",
   "metadata": {},
   "outputs": [],
   "source": [
    "help(Phi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "22880715",
   "metadata": {},
   "outputs": [],
   "source": [
    "A=MatrixSymbol(\"A\",n,n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d5705722",
   "metadata": {},
   "outputs": [],
   "source": [
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3b212a94",
   "metadata": {},
   "outputs": [],
   "source": [
    "C=Point(2/sqrt(3),2,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9deda1bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "B=Point(2/sqrt(3),-2,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "daa4e79d",
   "metadata": {},
   "outputs": [],
   "source": [
    "A1=Point(0,0,4*sqrt(6)/3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b36dff7f",
   "metadata": {},
   "outputs": [],
   "source": [
    "C1=Point(2*sqrt(3),2,4*sqrt(6)/3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c8cbf72c",
   "metadata": {},
   "outputs": [],
   "source": [
    "B-C"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f8a922c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "B-A1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "da1d9967",
   "metadata": {},
   "outputs": [],
   "source": [
    "linsolve((Matrix([B-C,B-A1]),Matrix([0,0])),[x,y,z])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1fb923c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "linsolve((Matrix([B-C1,B-A1]),Matrix([0,0])),[x,y,z])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "62cc837d",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=2*x*exp(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "43ac5446",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "05d82db9",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr_g=expr-a*(x+1)**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7adff8e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr_g"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "799630e5",
   "metadata": {},
   "outputs": [],
   "source": [
    "diff(expr_g,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d8d0c10a",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr_g,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "82f5d36c",
   "metadata": {},
   "outputs": [],
   "source": [
    "help(Curve)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d5ac5f5f",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy.stats import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "19966409",
   "metadata": {},
   "outputs": [],
   "source": [
    "help(FiniteRV)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1381e990",
   "metadata": {},
   "outputs": [],
   "source": [
    "density={0:S(1)/27,1:S(2)/27,2:S(8)/81,3:S(64)/81}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "776fee4b",
   "metadata": {},
   "outputs": [],
   "source": [
    "X=FiniteRV(\"X\",density)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "54ea548a",
   "metadata": {},
   "outputs": [],
   "source": [
    "E(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fe2d3f03",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy.abc import k,t,l,m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ecc8835b",
   "metadata": {},
   "outputs": [],
   "source": [
    "l=Line(y-k*x-m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a4f7c221",
   "metadata": {},
   "outputs": [],
   "source": [
    "e=Ellipse(Point(0,0),3,sqrt(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b07fbed2",
   "metadata": {},
   "outputs": [],
   "source": [
    "line_and_quadratic(l,e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0649f7e0",
   "metadata": {},
   "outputs": [],
   "source": [
    "q=QuadraticFunction(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8637c70b",
   "metadata": {},
   "outputs": [],
   "source": [
    "q.roots.args[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "79ed2e31",
   "metadata": {},
   "outputs": [],
   "source": [
    "x1,x2=_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7c840b83",
   "metadata": {},
   "outputs": [],
   "source": [
    "x1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8d189481",
   "metadata": {},
   "outputs": [],
   "source": [
    "x2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2cc77a5d",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=(k*x1+m)*(k*x2+m)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f5d8f8ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(expr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6749b9d7",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr2=(x1-3)*(x2-3)*(-5)/3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "270c69c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(expr2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1ee6f3ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(fraction(simplify(expr2-expr))[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6930e7ef",
   "metadata": {},
   "outputs": [],
   "source": [
    "from excel_function_package.trig import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "93eb09e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "rad2deg(N(acos(-1/S(3))),format=\"second\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e291d40b",
   "metadata": {},
   "outputs": [],
   "source": [
    "rad2deg(N(atan(sqrt(2))),format=\"second\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "82c19c0f",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy.abc import x,y,z"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b77addee",
   "metadata": {},
   "outputs": [],
   "source": [
    "q=QuadraticFunction((2-x)*x-(x/2)**2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "361abd24",
   "metadata": {},
   "outputs": [],
   "source": [
    "q.symmetry_equation()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a8aba9d9",
   "metadata": {},
   "outputs": [],
   "source": [
    "%aimport excel_function_package.chi_square_test\n",
    "from excel_function_package.chi_square_test import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7937132e",
   "metadata": {},
   "outputs": [],
   "source": [
    "chi_squared_of_error_probability(0.15)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c6f38842",
   "metadata": {},
   "outputs": [],
   "source": [
    "N(chi_squared_of_error_probability(S(25)/1000))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b5726494",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=(x+1)/(x-1)*ln(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "62417c79",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d3cd1a22",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "03bb6049",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(2,expr,(x,0.1,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0f91886c",
   "metadata": {},
   "outputs": [],
   "source": [
    "help(sieve)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d8801d2d",
   "metadata": {},
   "source": [
    "## T8恩施卷"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7d303541",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=exp(x)*sin(2*x)/(exp(2*x)-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2c5fd487",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fbd0ff9d",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(expr,(x,-5,5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6948e8e0",
   "metadata": {},
   "outputs": [],
   "source": [
    "expand((3*x-y-2)**6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "307035da",
   "metadata": {},
   "outputs": [],
   "source": [
    "f=lambda n: n-2 if n%2==0 else n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b8df0b5c",
   "metadata": {},
   "outputs": [],
   "source": [
    "def test(n):\n",
    "    if(n%2==0):\n",
    "        return n-2\n",
    "    else:\n",
    "        return n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a7fa1b06",
   "metadata": {},
   "outputs": [],
   "source": [
    "sum([test(i) for i in range(1,17)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aa894237",
   "metadata": {},
   "outputs": [],
   "source": [
    "sum(sequence(2**n,(n,1,4)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "db323968",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=cos(sqrt(2)*x)-ln(1-x**2)\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bebd64c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(expr,(x,-2,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "06515f52",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr1=diff(expr,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "70a7a7a3",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "46364fc1",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr2=diff(expr1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "39938013",
   "metadata": {},
   "outputs": [],
   "source": [
    "(expr2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8377fb7f",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr3=diff(expr2)\n",
    "expr3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99514bc7",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(expr1,expr2,expr3,(x,-1/S(2),1/S(2)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3f4745f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "q=QuadraticFunction(a,b,c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "60191fed",
   "metadata": {},
   "outputs": [],
   "source": [
    "q.symmetry_equation()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e29fecd8",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=1/(a**x-1)+S(1)/2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2cb501a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b86c082d",
   "metadata": {},
   "outputs": [],
   "source": [
    "apart(expr.subs(x,-x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5e8c4d86",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=ln(x)-(x+1)/(x-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e7e2043e",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "25838bf8",
   "metadata": {},
   "outputs": [],
   "source": [
    "diff(expr,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1ad4f945",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a617777d",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(x**2<abs(x-1),x,Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f7b5bcdf",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(x**2,1-x,(x,-2,1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8fc7d538",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=ln(abs(a+1/(1-x)))+b\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a6e59f42",
   "metadata": {},
   "outputs": [],
   "source": [
    "(expr.subs(x,-x)+expr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d5530919",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr.subs({x:0,a:-1/S(2)})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dbe1f7fa",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(logcombine(expr.subs({a:-1/S(2),b:ln(2)})))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f6eefefb",
   "metadata": {},
   "outputs": [],
   "source": [
    "check=_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e035dd0c",
   "metadata": {},
   "outputs": [],
   "source": [
    "(3-2*0.301)/0.017"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1047253e",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy import N"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ed5b4f70",
   "metadata": {},
   "outputs": [],
   "source": [
    "N((3-2*log(2,10))/log(1.04,10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b0386b61",
   "metadata": {},
   "outputs": [],
   "source": [
    "N(ln(2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0c75ab0b",
   "metadata": {},
   "outputs": [],
   "source": [
    "3/0.69"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4068c7be",
   "metadata": {},
   "outputs": [],
   "source": [
    "N(3/ln(2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2b9f0898",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=2*ln(1+t)-sqrt(1+4*t)+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d289de1b",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(diff(expr,t),(t,0,0.4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "744160c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=2*ln((x**2+3)/4)-x+1\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2c1bb314",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b8d7275c",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=(3-x)*ln(x+3)\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "05f4228b",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(diff(expr,x,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d734d58",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(sin(2*pi*x),1/x,(x,1/2,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "880ba752",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=max(x**2,3-2*x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cf9ebb71",
   "metadata": {},
   "outputs": [],
   "source": [
    "def max_expr(x):\n",
    "    if(x**2-(3-2*x)>=0):\n",
    "        return x**2\n",
    "    else:\n",
    "        return 3-2*x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38ecf2d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(max_expr,(x,-5,5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "84d23586",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=Max(Abs(x)**2,3-2*Abs(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ea45a415",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(expr,3/2,(x,-5,5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5c411c3f",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(Eq(x**2,3-2*x),x,Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aafccba0",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=Piecewise((-x**2+4*x,x<=4),(Abs(log(x-4,2)),True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "28a2c5c5",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(expr,4,(x,-2,8))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8c5538a7",
   "metadata": {},
   "outputs": [],
   "source": [
    "t=symbols(\"t\",positive=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ea37e96c",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(expr-t,x,Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "52403da5",
   "metadata": {},
   "outputs": [],
   "source": [
    "answer=_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4fbf8d93",
   "metadata": {},
   "outputs": [],
   "source": [
    "answer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9b4c9c20",
   "metadata": {},
   "outputs": [],
   "source": [
    "x4,x3=answer[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "364746c9",
   "metadata": {},
   "outputs": [],
   "source": [
    "x4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f36814b7",
   "metadata": {},
   "outputs": [],
   "source": [
    "x2,x1=answer[1].args[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fcfc93e4",
   "metadata": {},
   "outputs": [],
   "source": [
    "x1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "44d4e014",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=(sqrt(2)+x1)*(sqrt(2)-x2)+4*x3+x4/4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f8d9732c",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(expr,(t,0,4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7b7dd0fc",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "simplify(expr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a02e5b11",
   "metadata": {},
   "outputs": [],
   "source": [
    "diff(_,t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5118c426",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(_,(t,0,4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7e46882e",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr.subs(t,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "91a66649",
   "metadata": {},
   "outputs": [],
   "source": [
    "f=x**2/2+3*x*a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3f2be2d2",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(diff(f,x).subs(x,3)-a,a,Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a0b0b379",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_tangent(f.subs(a,-3/S(2)),x,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5715b895",
   "metadata": {},
   "outputs": [],
   "source": [
    "del y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "29346608",
   "metadata": {},
   "outputs": [],
   "source": [
    "y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0412fc9e",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy.core.symbol import _symbol"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f5d43477",
   "metadata": {},
   "outputs": [],
   "source": [
    "y=_symbol(\"y\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b834818b",
   "metadata": {},
   "outputs": [],
   "source": [
    "y=4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6efafaf7",
   "metadata": {},
   "outputs": [],
   "source": [
    "type(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9c738a98",
   "metadata": {},
   "outputs": [],
   "source": [
    "del x\n",
    "x=_symbol(\"x\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "38b0e5c8",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(function_tangent(x*exp(x),x,-2),x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "144248ff",
   "metadata": {},
   "outputs": [],
   "source": [
    "help(function_tangent)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cc57a053",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=(x+a)*exp(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5608fee4",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "201d1831",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2ec3e772",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_tangent(expr,x,t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "83c1be4e",
   "metadata": {},
   "outputs": [],
   "source": [
    "_.subs({x:0,y:0})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "076b59d7",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "73868d9b",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr_f=x**2-m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eb6a79d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr_f"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b8151f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr_g=6*ln(x)-4*x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cde569be",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr_g"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9599dc8f",
   "metadata": {},
   "outputs": [],
   "source": [
    "check=expr_f-expr_g"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "191c5c33",
   "metadata": {},
   "outputs": [],
   "source": [
    "diff(check,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d17b7a6b",
   "metadata": {},
   "outputs": [],
   "source": [
    "Eq(expr_g.subs(x,1),expr_f.subs(x,1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "894a764c",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_tangent(x*exp(x),x,-2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6c9412a2",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(_.subs(x,1),y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "737d017a",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=(1-x**2+x)*exp(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "875a0c77",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2c42a4ab",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(expr,x,Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9533f329",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=x*ln(1+x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "685277ba",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_tangent(expr,x,-1/S(2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "710b9689",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=x*exp(a*x)-exp(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f6b371c7",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a575a03b",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_monotonyset(expr.subs(a,1),x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "703a3835",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(expr.subs(a,1),(x,-3,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a0f25763",
   "metadata": {},
   "outputs": [],
   "source": [
    "diff(expr,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6643ec26",
   "metadata": {},
   "outputs": [],
   "source": [
    "diff(expr,x,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "077c80cd",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=-x*exp(a*x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a242ec0a",
   "metadata": {},
   "outputs": [],
   "source": [
    "a=symbols(\"a\",real=True,positive=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1365b241",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d54f2c26",
   "metadata": {},
   "source": [
    "# There is a BUG!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c4f6a0e5",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_monotonyset(expr,x,Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "170d7064",
   "metadata": {},
   "outputs": [],
   "source": [
    "help(sign)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "59fcbd4e",
   "metadata": {},
   "outputs": [],
   "source": [
    "sign(x**2,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9bc5a4bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "797d3cbc",
   "metadata": {},
   "outputs": [],
   "source": [
    "a=symbols(\"a\",real=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b558bb2",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=a*ln(x)+1/x+4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2f2c7860",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "85454775",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e30a32b6",
   "metadata": {},
   "outputs": [],
   "source": [
    "check=expr-1/x-(x+1)**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8b1a6343",
   "metadata": {},
   "outputs": [],
   "source": [
    "check"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0f09d62f",
   "metadata": {},
   "outputs": [],
   "source": [
    "diff(check,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ef7fa2b0",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(_,x,Interval.open(0,oo)).args[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6755a99e",
   "metadata": {},
   "outputs": [],
   "source": [
    "answer=list(_)[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "182ce92d",
   "metadata": {},
   "outputs": [],
   "source": [
    "answer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c42c84b1",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(solveset(check.subs(x,exp(1))>0,a,Reals))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fb9a6896",
   "metadata": {},
   "outputs": [],
   "source": [
    "check.subs(x,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1d864282",
   "metadata": {},
   "outputs": [],
   "source": [
    "check.subs(x,exp(1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "81a46c65",
   "metadata": {},
   "outputs": [],
   "source": [
    "dir(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1a5039f3-053d-49f0-8af9-ca24bed205e3",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "help(Symbol)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dabbd9da-60fd-452f-8e10-eaa23b76fb3a",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=a*(x-ln(x+1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3f9b8cd5",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7d80d25a",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr1=expr-ln(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "db77d006",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "86c680b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr1,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c518463a",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(_,x,Interval.open(0,oo))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "33b48628",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr2=expr-sin(x)+x*cos(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a5fd4a99",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec95d9d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "diff(expr2,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4d367511",
   "metadata": {},
   "outputs": [],
   "source": [
    "fraction(factor(diff(expr2,x)))[0]/x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f5045665",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=2*a*ln(x)-x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb00f529",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b069aabf",
   "metadata": {},
   "outputs": [],
   "source": [
    "diff(expr,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8cafb832",
   "metadata": {},
   "outputs": [],
   "source": [
    "diff(expr,x).subs(x,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2ce45824",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr.subs(a,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5393a1dd",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_range(expr.subs(a,1),x,Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a9fe4c76",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=x**3-x+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a0732723",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a11fef66",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr.subs(x,1/sqrt(3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "75911eb0",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_tangent(expr,x,-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "75f96324",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=x/sin(x)+cos(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01c81a21",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "98adc253",
   "metadata": {},
   "outputs": [],
   "source": [
    "trigsimp(factor(diff(expr,x)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "06362e72",
   "metadata": {},
   "outputs": [],
   "source": [
    "check=expr.subs(x,pi-x)-expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "39f714f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "check"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0a072a18",
   "metadata": {},
   "outputs": [],
   "source": [
    "trigsimp(factor(trigsimp(diff(check,x))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "58c789f5",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=x**2/2-x-a*ln(x-a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "85af5487",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e486b721",
   "metadata": {},
   "outputs": [],
   "source": [
    "diff(expr,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6222f25a",
   "metadata": {},
   "outputs": [],
   "source": [
    "collect(factor(diff(expr,x)),x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7d9eb81f",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(_,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f83e4738",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_range(expr,x,Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a00baf82",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr_g=expr.subs(x,x+a)-a*(x+a/2-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99c5f5bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(expr_g)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "02babd0c",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(diff(_,x),x,Interval.open(0,oo))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3da3c1e9",
   "metadata": {},
   "outputs": [],
   "source": [
    "x1,x2=_.args[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b5827b69",
   "metadata": {},
   "outputs": [],
   "source": [
    "x1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "68b9d57f",
   "metadata": {},
   "outputs": [],
   "source": [
    "x2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fc5b262a",
   "metadata": {},
   "outputs": [],
   "source": [
    "delta=expr.subs(x,x1)-expr.subs(x,x2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb1cae62",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(delta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5e03fb70",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=(x-m)*exp(x)-x**2/m+n*x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "48e26b04",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1c1a223c",
   "metadata": {},
   "outputs": [],
   "source": [
    "diff(expr,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "95113f3f",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_tangent(expr,x,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "33023096",
   "metadata": {},
   "outputs": [],
   "source": [
    "dates={m:2,n:1}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c93667f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr.subs(dates)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5c2fd662",
   "metadata": {},
   "outputs": [],
   "source": [
    "checks=factor(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77cf56f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "checks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4d88575b",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(checks,(x,-2,2.4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4dc0f299",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(checks,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c5ad9e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=a*ln(x)+b/x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "906362cb",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a3868c8e",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "efc53c27",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_range(ln(x)+S(1)/2/x**2+S(3),x,Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a05d0db3",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(-4*x**3+3*x,(x,-2,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cdecaca6",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(diff(-4*x**3+3*x,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "45de0f01",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy import N"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8eb73a51",
   "metadata": {},
   "outputs": [],
   "source": [
    "N(exp(1)-3-2/exp(3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7f02d841",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=exp(x)/x-ln(x)+x-a\n",
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d01cfb6a",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f47c0b6b",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr.subs(x,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "594843af",
   "metadata": {},
   "outputs": [],
   "source": [
    "check=expr-expr.subs(x,1/x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88e0d6bf",
   "metadata": {},
   "outputs": [],
   "source": [
    "(check)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7467e451",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(check,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f4b41ca2",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr_d=fraction(_)[0]/(1-x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ba15d84f",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(expr_d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4fee2a6e",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(simplify(expr_d),x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5c4a3795",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr_g=exp(x)/x-x*exp(1/x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "02123c26",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr_g"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "48a4dbc3",
   "metadata": {},
   "outputs": [],
   "source": [
    "diff(expr_g,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ecb9fbd",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr_g,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c4057755",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=x**3+a*x+2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b3c8c101",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3bf406b4",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(factor(diff(expr,x)),x,Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a7d540d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(expr.subs(x,sqrt(-a/3)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "affdafb6",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=Piecewise((exp(x)-exp(-x),x>=0),(-x-2-4/x,True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "88e14584",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9180ce13",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr.subs(x,-2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fbb2be90",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(expr,(x,-8,-0.2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b6f1705",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(expr,(x,0.2,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b93ef154",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=Piecewise((3*x,x<=0),((x-2*exp(1))*ln(x),True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a88c124f",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5be91a5e",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(Abs(expr),(x,-3,9))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "711ffd23",
   "metadata": {},
   "outputs": [],
   "source": [
    "diff((x-2*exp(1))*ln(x),x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f6a1f1a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr.subs(x,exp(1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bac79d4c",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=ln(1+x)+a*x*exp(-x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "54879c5b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "390284bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_tangent(expr.subs(a,1),x,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0c289773",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "60a7252b",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=exp(x-1)+exp(1)/ln(2)*(ln(x)+1)-a*x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "607beb6f",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3d392d9e",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_range(expr.subs(a,3),x,Interval.open(0,oo))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b3c89ea2",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr.subs(a,3),x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2758a036",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr_d=fraction(_)[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d9d72ac7",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(expr_d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8f639269",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr_d,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "17a87131",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6784d48d",
   "metadata": {},
   "outputs": [],
   "source": [
    "check=fraction(factor(diff(expr,x)))[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "32497953",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(check)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "297e3f95",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(check,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f2276b25",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_monotonyset(diff(expr,x,2),x,Interval.open(0,oo))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f1adde59",
   "metadata": {},
   "outputs": [],
   "source": [
    "N(4*ln(2)-exp(1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "572da761",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr_a=list(solveset(expr,a))[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fc176dd5",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr_a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9acc69a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(expr_a,(x,0.6,2.8))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c70d3160",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr_a,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0b5f92b2",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(fraction(factor(diff(expr_a,x)))[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "da188a0e",
   "metadata": {},
   "outputs": [],
   "source": [
    "diff(_,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "06d8a961",
   "metadata": {},
   "outputs": [],
   "source": [
    "N(ln(2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6f882f1f",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=a*ln(x)+x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8dbf800d",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1bf16720",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5add33b2",
   "metadata": {},
   "outputs": [],
   "source": [
    "check=(1+b)*(1-t)/(t+b)+ln(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ae062351",
   "metadata": {},
   "outputs": [],
   "source": [
    "check\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d533cb82",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(diff(check,t)-1/t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eb24dbd3",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(check,t))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c4d157b3",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=a*ln(x)+x+2/x+2*a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e0c64146",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "35c2d0ee",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "21ca6603",
   "metadata": {},
   "outputs": [],
   "source": [
    "check=simplify(expr-(x+(exp(x)+2)/x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e5ffeb9d",
   "metadata": {},
   "outputs": [],
   "source": [
    "check"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a7f2f82f",
   "metadata": {},
   "outputs": [],
   "source": [
    "question=exp(x)/(x*(2+ln(x)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fa09ac50",
   "metadata": {},
   "outputs": [],
   "source": [
    "question"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "570e6feb",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(question,(x,0.2,4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "be87caa5",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(question,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77694f4b",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(function_range(exp(x)/((x+1)**2),x,Interval.open(0,oo)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "387f294e",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=a*x+b/x+c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5ae7b03c",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01dafc53",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_tangent(expr,x,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7c34663b",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_list={b:a-1,c:1-2*a}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01104986",
   "metadata": {},
   "outputs": [],
   "source": [
    "checks=expr.subs(data_list)-ln(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4556c5dc",
   "metadata": {},
   "outputs": [],
   "source": [
    "checks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e364a1da",
   "metadata": {},
   "outputs": [],
   "source": [
    "checks.subs(x,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0818f3d6",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "factor(diff(checks,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2515ba3b",
   "metadata": {},
   "outputs": [],
   "source": [
    "checks.subs(a,1/S(2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "542aa16f",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=Abs(x*exp(x)-a)-a*x*(ln(x)+1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ef5165c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fdf13f5f",
   "metadata": {},
   "outputs": [],
   "source": [
    "check=expr.subs(a,-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ccf34841",
   "metadata": {},
   "outputs": [],
   "source": [
    "check"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "61a8d038",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(check,x*(exp(x)+2),(x,0.2,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f218cf36",
   "metadata": {},
   "outputs": [],
   "source": [
    "check1=exp(x)/(1/x+ln(1/x)-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a29ef544",
   "metadata": {},
   "outputs": [],
   "source": [
    "check1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d47ee3b1",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(check1,(x,0.2,0.9))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b4ea5e19",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(check1,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ee81e771",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_list={cos(x)*sin(y):S(1)/6}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0b897d0c",
   "metadata": {},
   "outputs": [],
   "source": [
    "expand_trig(sin(x-y)).subs(data_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9feb6fc2",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_list[sin(x)*cos(y)]=1/S(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1f51b60b",
   "metadata": {},
   "outputs": [],
   "source": [
    "data_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2956d5cf",
   "metadata": {},
   "outputs": [],
   "source": [
    "expand_trig(sin((x+y))).subs(data_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cf654d5a",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=cos(x)-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "735e6628",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c7fe3993",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(expr,(x,0,pi*2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "60e1d2e6",
   "metadata": {},
   "outputs": [],
   "source": [
    "help(function_transfer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4501b5a5",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=cos(2*x+pi/6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f25c6da3",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_transfer(expr,x,move=-pi/6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9d889da7",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(_-(x-1)/2,x,Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8c76f37a",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(-sin(2*x),(x-1)/2,(x,-2*pi,2*pi))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6258ee21",
   "metadata": {},
   "outputs": [],
   "source": [
    "help(Triangle)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7e3b7475",
   "metadata": {},
   "outputs": [],
   "source": [
    "help(degree)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2fad47bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "deg(pi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1537682c",
   "metadata": {},
   "outputs": [],
   "source": [
    "tri=Triangle(sas=(1,deg(2*pi/3),2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ebdb075e",
   "metadata": {},
   "outputs": [],
   "source": [
    "tri.angles[Point(2,0)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "66511c90",
   "metadata": {},
   "outputs": [],
   "source": [
    "tan(tri.angles[Point(2,0)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1596e0cd",
   "metadata": {},
   "outputs": [],
   "source": [
    "tri.sides[1].length"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "37ebb2eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "help(MatrixSymbol)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fd22ee0e",
   "metadata": {},
   "outputs": [],
   "source": [
    "ma=Matrix([1,2,3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd2b8bc1",
   "metadata": {},
   "outputs": [],
   "source": [
    "ma"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7e051a33",
   "metadata": {},
   "outputs": [],
   "source": [
    "ma.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "84eb26db",
   "metadata": {},
   "outputs": [],
   "source": [
    "expand((b+c)**2/4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "71854e73",
   "metadata": {},
   "outputs": [],
   "source": [
    "nonlinsolve([x*y-4,x**2+y**2-8],[x,y],Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8da746ac",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=sin(2*x)/(1+cos(2*x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "78913dca",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dc8107ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "trigsimp(expr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0a243ced",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "expr=(1-x)/(1+x)*x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ad95eb51",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb74ff77",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "function_range(1-2*expr,x,Interval.open(0,1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f665f68c",
   "metadata": {},
   "outputs": [],
   "source": [
    "expand(_.inf)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a2f27b6f",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(expr,(x,0,1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ef32ec4b",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(2+(2-sqrt(3))**2/2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3d2ae2b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "N(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fd871ae0",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_range(2*(x+sqrt(1-x)),x,Interval.open(0,1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5270d1dc",
   "metadata": {},
   "outputs": [],
   "source": [
    "q=QuadraticFunction(-2,2,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "805d8ce5",
   "metadata": {},
   "outputs": [],
   "source": [
    "q.symmetry_equation()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aca3fbc7",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=tan(x-pi/6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "781f0d1f",
   "metadata": {},
   "outputs": [],
   "source": [
    "expand_trig(expr).subs(cot(x),2/sqrt(3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "864631af",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy.abc import alpha"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fef088c5",
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha=atan(-1/S(2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "915fbe83",
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1d313665",
   "metadata": {},
   "outputs": [],
   "source": [
    "trigsimp(sin(pi/2-2*alpha))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f4d93f41",
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha=atan(9/-S(3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00bdeeb4",
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "216f146c",
   "metadata": {},
   "outputs": [],
   "source": [
    "expand_trig(trigsimp(expand_trig(tan(2*alpha+3*pi/4))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "856d51db",
   "metadata": {},
   "outputs": [],
   "source": [
    "trigsimp(expand_trig(sin(2*alpha)+3*cos(2*alpha)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "878def9f",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy.abc import beta"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "746e28f0",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "alpha=asin(4*sqrt(3)/7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01ce0eb8",
   "metadata": {},
   "outputs": [],
   "source": [
    "beta=acos(13/S(14))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "349ae4bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "trigsimp(cos(alpha-beta))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d93a13c9",
   "metadata": {},
   "outputs": [],
   "source": [
    "sin(beta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "16e85f51",
   "metadata": {},
   "outputs": [],
   "source": [
    "trigsimp(sin(alpha+beta))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3bfbb0d5",
   "metadata": {},
   "outputs": [],
   "source": [
    "11/_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f437c7e1",
   "metadata": {},
   "outputs": [],
   "source": [
    "r=_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ba057d9f",
   "metadata": {},
   "outputs": [],
   "source": [
    "r*sin(alpha)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "19ada943",
   "metadata": {},
   "outputs": [],
   "source": [
    "r*sin(beta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d4f2657",
   "metadata": {},
   "outputs": [],
   "source": [
    "(1/S(2))*(56/S(5))*(21/S(5))*(55*sqrt(3)/98)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb770c4d",
   "metadata": {},
   "outputs": [],
   "source": [
    "tri=Triangle(asa=(deg(alpha),11,deg(beta)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "56ebae83",
   "metadata": {},
   "outputs": [],
   "source": [
    "for segment in tri.sides:\n",
    "    print(trigsimp(segment.length))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "715329ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "tri.area"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "32ce12dc",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy.abc import omega"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "37fb7aa3",
   "metadata": {},
   "outputs": [],
   "source": [
    "omega"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ef1c11ed",
   "metadata": {},
   "outputs": [],
   "source": [
    "solve_univariate_inequalities([2*pi/3<2*pi/omega,2*pi/omega<pi],omega)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "357efc0f",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_range(omega*3*pi/2+pi/4,omega,Interval.open(2,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "72bf6226",
   "metadata": {},
   "outputs": [],
   "source": [
    "help(imageset)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8f45708f",
   "metadata": {},
   "outputs": [],
   "source": [
    "Intersection(_,imageset(lambda k:k*pi,Naturals0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d58985b7",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(omega*3*pi/2+pi/4-4*pi,omega)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "89488f43",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=sin(omega*(x-pi/6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "08b27854",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5790e914",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "solveset(Eq(expr.subs(x,5*pi/3),-1),omega)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d511ca3e",
   "metadata": {},
   "outputs": [],
   "source": [
    "count=0\n",
    "for answer in _:\n",
    "    print(answer)\n",
    "    count+=1\n",
    "    if(count>5):\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c894ed08",
   "metadata": {},
   "outputs": [],
   "source": [
    "35*pi/9+11*pi/18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3a648c1b",
   "metadata": {},
   "outputs": [],
   "source": [
    "35*pi/9-7*pi/18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "79b5f8b9",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=sin(omega*x+pi/3)+cos(omega*x-pi/6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1315cc38",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01d99349",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr_g=function_transfer(expr,x,scale=S(1)/2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ad8aef3",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr_g"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f5113dc1",
   "metadata": {},
   "outputs": [],
   "source": [
    "list(expr_g.atoms(Function))[0].args[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1a67ac17",
   "metadata": {},
   "outputs": [],
   "source": [
    "_.subs(x,pi/12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "19dfd5f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "solve_univariate_inequalities([pi/2<_,_<=3*pi/2],omega)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "55b5ae97",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=2*sin(omega*x-pi/6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aedd6c01",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "51423959",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(expr.subs(omega,6/5),(x,-pi,pi))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c70f3c8d",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr.subs(x,5*pi/12)-sqrt(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9d0eb227",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(expr.subs(x,5*pi/12)-sqrt(3),omega,)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77eb6733",
   "metadata": {},
   "outputs": [],
   "source": [
    "_.args[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1bb656cb",
   "metadata": {},
   "outputs": [],
   "source": [
    "Eq(acos(-sqrt(3)/2),list(expr.subs(x,5*pi/12).atoms(Function))[0].args[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "61e3082a",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(_,omega)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fb5b63d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "final=expr.subs(omega,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "954623a1",
   "metadata": {},
   "outputs": [],
   "source": [
    "final"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ed313d67",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(final,x,Interval.Lopen(0,pi/6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "abf59557",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_transfer(function_transfer(2*cos(x),x,scale=S(1)/2),x,move=pi/3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "290fb8de",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(_,(x,-pi,pi))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6adedca3",
   "metadata": {},
   "outputs": [],
   "source": [
    "is_decreasing(final,Interval(pi/2,2*pi/3),x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7fb2e4c7",
   "metadata": {},
   "outputs": [],
   "source": [
    "help(is_decreasing)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "df05e91f",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=3*sin(2*x+pi/4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e9a84a9f",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c5c612ca",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_transfer(expr,x,move=pi/6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "48bd7391",
   "metadata": {},
   "outputs": [],
   "source": [
    "p=(plot_parametric((-5*pi/24,t),(t,-3,3)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f8fb583d",
   "metadata": {},
   "outputs": [],
   "source": [
    "p1=plot(function_transfer(expr,x,move=pi/6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8a601178",
   "metadata": {},
   "outputs": [],
   "source": [
    "(p.append(p1[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "86ddd08b",
   "metadata": {},
   "outputs": [],
   "source": [
    "p.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1c2e2ced",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=cos(2*x-pi/6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4ab19eb5",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "41fab584",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(expr,(x,-2,0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "61bd9dfe",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=2*sin(x)*Abs(cos(x))+sqrt(3)*cos(2*x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "44f1b3a2",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8f02eb33",
   "metadata": {},
   "outputs": [],
   "source": [
    "p=plot(expr,(x,0,4*pi))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "362e48ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "p1=plot_parametric((pi/12,t),(2*pi,t),(13*pi/6,t),(5*pi/2,t),(t,-3,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "845f0e21",
   "metadata": {},
   "outputs": [],
   "source": [
    "p.extend(p1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3d2ad41a",
   "metadata": {},
   "outputs": [],
   "source": [
    "p.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9606a0af",
   "metadata": {},
   "outputs": [],
   "source": [
    "is_decreasing(expr,Interval(13*pi/6,5*pi/2),x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0892fda6",
   "metadata": {},
   "outputs": [],
   "source": [
    "QuadraticFunction(6,-1,-1).roots"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9da1218e",
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha=atan(-3)-pi/4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "408c622d",
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "12a584e4",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=3*sin(x)**2-sin(pi+x)*cos(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "17889b95",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "66272897",
   "metadata": {},
   "outputs": [],
   "source": [
    "(expand_trig(expr.subs(x,alpha)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0a729fde",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(expand_trig(tan(2*x)-1/S(2)),tan(x),Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c5d7b828",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=(2*x-1+x**2)/(1+x**2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77c4e758",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(expr.subs(x,sqrt(5)-2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "33e61ff1",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq=Eq(sin(x+y)+cos(x+y),2*sqrt(2)*cos(x+pi/4)*sin(y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb2367cb",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3b142fea",
   "metadata": {},
   "outputs": [],
   "source": [
    "trigsimp(eq)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9179386d",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq=Eq(tan(x),(sqrt(2)*cos(x)+1)/(sqrt(3)-sqrt(2)*sin(x)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4d583e1c",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b8aa47f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq.subs(tan(x),sin(x)/cos(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a0b73872",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq_constant=Eq(sin(x)**2+cos(x)**2,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2221d059",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq_constant"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9de85d05",
   "metadata": {},
   "outputs": [],
   "source": [
    "nonlinsolve([eq_constant,eq.subs(tan(x),sin(x)/cos(x))],[sin(x),cos(x)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d18aee15",
   "metadata": {},
   "outputs": [],
   "source": [
    "a1,a2=_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "04c560fd",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(a1[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bc38886b",
   "metadata": {},
   "outputs": [],
   "source": [
    "check=eq.subs(tan(x),sin(x)/cos(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8b134ad8",
   "metadata": {},
   "outputs": [],
   "source": [
    "check"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "51da312a",
   "metadata": {},
   "outputs": [],
   "source": [
    "def equation_transfer(eq: Equality, **kwargs) -> Equality:\n",
    "    lhs = fraction(eq.lhs)\n",
    "    rhs = fraction(eq.rhs)\n",
    "    if kwargs.get(\"expr\")== True:\n",
    "        return lhs[0] * rhs[1] - lhs[1] * rhs[0]\n",
    "\n",
    "    return Eq(lhs[0] * rhs[1], lhs[1] * rhs[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a10b09e6",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(equation_transfer(check,expr=True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b6a45e98",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "trigsimp(cos(acos(1/S(3))-pi/6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00678427",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1c7351e5",
   "metadata": {},
   "outputs": [],
   "source": [
    "trigsimp(tan(atan(-2/S(3))-5*pi/4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1d7365d",
   "metadata": {},
   "outputs": [],
   "source": [
    "equation_transfer(Eq(1+sqrt(3)/tan(rad(80)),1/sin(x)),expr=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "df197e67",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(_,sin(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ace4e7f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "trigsimp(list(_)[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d5c21678",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy import N"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f041c95e",
   "metadata": {},
   "outputs": [],
   "source": [
    "help(N)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e196b721",
   "metadata": {},
   "outputs": [],
   "source": [
    "trigsimp(simplify((_.subs(tan(pi/18),sin(pi/18)/cos(pi/18)))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "994f5095",
   "metadata": {},
   "outputs": [],
   "source": [
    "QuadraticFunction(3,5,-2).roots"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6d84af3a",
   "metadata": {},
   "outputs": [],
   "source": [
    "1-2*(1/S(3))**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1d910ae0",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq=Eq((1-cos(2*x))/sin(2*x),(cos(x)-sin(x))/cos(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a74d2dae",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c5d42a52",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(equation_transfer(eq,expr=True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a5c2bb60",
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha=asin(1/S(3))-pi/6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "31f0a2e7",
   "metadata": {},
   "outputs": [],
   "source": [
    "alpha"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b6a0f7df",
   "metadata": {},
   "outputs": [],
   "source": [
    "cos(2*pi/3-2*alpha)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "46dbe41d",
   "metadata": {},
   "outputs": [],
   "source": [
    "trigsimp(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "20b42a89",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(1-2*x**2-(1+sqrt(5))/4,x,Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "61b7e85d",
   "metadata": {},
   "outputs": [],
   "source": [
    "a1,a2=_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99d6fa75",
   "metadata": {},
   "outputs": [],
   "source": [
    "a2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "42922cd2",
   "metadata": {},
   "outputs": [],
   "source": [
    "nsimplify(a2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8528c328",
   "metadata": {},
   "outputs": [],
   "source": [
    "expand_trig(sin(2*asin(sqrt(8)/3)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8c3ef0ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "expand_trig(sin(x/2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "83377ac3",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(expand_trig(cos(3*x))-cos(3*x),cos(x))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c92ac704",
   "metadata": {},
   "source": [
    "\n",
    "## 黄石T8联盟卷"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "27e208f3-86ac-4d9b-9fdc-218627f36a94",
   "metadata": {},
   "outputs": [],
   "source": [
    "A=solveset(x**2-3*x>=0,x,Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "752e8ea5-1b21-4fca-b52a-b0d8f1515643",
   "metadata": {},
   "outputs": [],
   "source": [
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "05fc8cbc-ee58-453e-8f98-4d42ac06c2f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "B=Union(solveset(x>2,x,Reals),solveset(x<=-2,x,Reals))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0b7b0c4a-0bf0-4dba-a4e7-a67258de7159",
   "metadata": {},
   "outputs": [],
   "source": [
    "B"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5008b219-16cb-45f2-beae-345ae64d239f",
   "metadata": {},
   "outputs": [],
   "source": [
    "A+B"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b5eb4ec2-7334-4ad3-8b11-196e9239682b",
   "metadata": {},
   "outputs": [],
   "source": [
    "A&B"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "688c197e-31b1-4f28-acf5-dfe6dc6f1a0f",
   "metadata": {},
   "outputs": [],
   "source": [
    "Intersection(Reals-Intersection(A,B),Union(A,B))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1f88efae-ffd5-4edd-a55b-aaa71d461d40",
   "metadata": {},
   "outputs": [],
   "source": [
    "z=(1+I**2023)/(2+I)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd9469af-96de-42ba-8521-eb2b6d5cb81d",
   "metadata": {},
   "outputs": [],
   "source": [
    "im(z-conjugate(z))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "15d6b37c-e10c-456f-8e4e-f6591b566e3a",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "98892820-a677-41cd-a111-25eead97b053",
   "metadata": {},
   "outputs": [],
   "source": [
    "A=Matrix([1,3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b68cf4a2-fdf9-4566-8ad7-3f0b61a51cac",
   "metadata": {},
   "outputs": [],
   "source": [
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "81b7705c-afd7-4eaf-9578-85fbeaa7f251",
   "metadata": {},
   "outputs": [],
   "source": [
    "B=Matrix([2,-2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3b99b2e9-eb7e-4bf6-a53c-a2cd2a312829",
   "metadata": {},
   "outputs": [],
   "source": [
    "B"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "97ede2e7-362c-4af9-b4c8-52da0960a482",
   "metadata": {},
   "outputs": [],
   "source": [
    "C=Matrix([p*A+B,A+q*B]).reshape(2,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7e2a063a-2765-4773-82ee-f2fba0dadfb2",
   "metadata": {},
   "outputs": [],
   "source": [
    "C"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8dc41e10-aa46-497c-9501-b45a7f24ea7b",
   "metadata": {},
   "outputs": [],
   "source": [
    "det(C)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "384807d8-3dd5-4a24-8085-008fcb52eab8",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq=Eq(9/S(10),(1/S(2))**(x/5730))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8881f1ca-4e91-4d7d-b5f2-2244d1d78c78",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "799974fa-e253-4a46-8ca5-bd976b0c6922",
   "metadata": {},
   "outputs": [],
   "source": [
    "answer,=solveset(eq,x,Reals)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b1666325-2651-42a8-ac13-10ef3f2e7fe7",
   "metadata": {},
   "outputs": [],
   "source": [
    "answer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "76c87c51-c6f5-4e06-9e2c-8d3e89150174",
   "metadata": {},
   "outputs": [],
   "source": [
    "expand_log(simplify(answer))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eea48d50-1865-4561-a62c-8bbf20196178",
   "metadata": {},
   "outputs": [],
   "source": [
    "expand_log(simplify(answer)).subs({log(2):0.301,log(3):0.477,log(10):1})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "218ec912-0bdc-41ff-b415-3e7eb0db1d38",
   "metadata": {},
   "outputs": [],
   "source": [
    "_/5730"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4e3a192d-7318-4756-ac60-5434005c6db2",
   "metadata": {},
   "outputs": [],
   "source": [
    "N(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ae20ab6a-1e07-4995-b10c-27cbb8dd39c9",
   "metadata": {},
   "outputs": [],
   "source": [
    "2023-871"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8b4db12c-53b5-441b-8946-c68ca1a224da",
   "metadata": {},
   "outputs": [],
   "source": [
    "5730*0.15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9b097769-073d-4fa1-bd10-17b1b33e4b66",
   "metadata": {},
   "outputs": [],
   "source": [
    "c=Circle(Point(4,3),1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d979ac5c-7b17-460e-9db2-4bb9df574d3c",
   "metadata": {},
   "outputs": [],
   "source": [
    "c.equation(x,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8f3e9a56-82ab-437b-b160-e885e055a6fc",
   "metadata": {},
   "outputs": [],
   "source": [
    "A=Point(-1,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5f908b37-9b83-4df8-9bfa-5fac9ff7d064",
   "metadata": {},
   "outputs": [],
   "source": [
    "B=Point(1,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c724fc20-36c0-4b38-80f3-4555bc843108",
   "metadata": {},
   "outputs": [],
   "source": [
    "P=Point(x,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ad545fd9-c078-46b6-bbdf-27f52540c7dd",
   "metadata": {},
   "outputs": [],
   "source": [
    "check=(P.distance(A))**2+(P.distance(B))**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "20581535-78c7-45ff-a29a-c4f1bf7394be",
   "metadata": {},
   "outputs": [],
   "source": [
    "expand(check-2*c.equation(x,y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e2c8d0d2-f70a-4294-b7a1-e0bc386eeb13",
   "metadata": {},
   "outputs": [],
   "source": [
    "l=Line(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "746a9f56-68dc-4017-8494-1eb6aa7e7fa0",
   "metadata": {},
   "outputs": [],
   "source": [
    "l.equation()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3b6f98b5-6b92-46be-b501-d5deef0d5009",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "plot_implicit(l.equation(x,y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2d878f98-02c2-4817-99d7-95840bf4ea77",
   "metadata": {},
   "outputs": [],
   "source": [
    "help(plot_implicit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cc4aa413-b42f-4273-82a7-1b32631921ed",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=(5+cos(theta))**2+(3+sin(theta))**2+(3+cos(theta))**2+(3+sin(theta))**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c11652b-9c47-4407-91af-17d45bcb616e",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ddaf3348-7546-42b7-ad71-30671c0a88f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "trigsimp(expr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fc552cb7-d174-41e2-ac3d-abebd9a90c79",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq=Eq(sqrt(3)*cos(x+y)-sin(x+y),2-4*cos(y-pi/3)*sin(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "796ee094-7fc6-4153-86b6-c7137174fb11",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "86b07c41-b0af-4f79-be21-8376821fdd99",
   "metadata": {},
   "outputs": [],
   "source": [
    "expand_trig(eq)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5fdedd8f-a4cd-4db8-8e8e-9ba288cb9657",
   "metadata": {},
   "outputs": [],
   "source": [
    "answer=_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "44c4fc1f-a385-4ce9-ab5e-5bda5ea51b63",
   "metadata": {},
   "outputs": [],
   "source": [
    "equation_transfer(answer,expr=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bcbd7755-fb11-4454-8b77-ae186671a71a",
   "metadata": {},
   "outputs": [],
   "source": [
    "check=_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "584b2014-516b-4e66-9b3d-3ebcd75711d7",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "simplify(check)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77dd4f3e-fcda-4e9e-8ec2-d70852a6ed89",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "help(dsolve)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5857a4f7-5183-4654-a40f-8e0608e92971",
   "metadata": {},
   "outputs": [],
   "source": [
    "type(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fc4b7a3b-5f6b-49b6-8814-0abc0228ca42",
   "metadata": {},
   "outputs": [],
   "source": [
    "rsolve(f(n+2)+(-1)**n*f(n)-4,f(n),{f(1):1})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "971cfce2-142d-4a51-a779-0f4ace9a665d",
   "metadata": {},
   "outputs": [],
   "source": [
    "rsolve(f(n+1)+f(n)-f(n+2),f(n),{f(1):1,f(2):1})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cf63f047-e654-4395-bb13-55e9991749b7",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "help(rsolve)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "32c7e6af-e318-46ff-831f-b4383b7fd835",
   "metadata": {},
   "outputs": [],
   "source": [
    "mu0,mu1=symbols(\"mu0:2\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "001eb372-06f8-41c9-939a-714cd49e1b17",
   "metadata": {},
   "outputs": [],
   "source": [
    "mu0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "69633eb7-ca28-4418-b0b0-60a781a3dd68",
   "metadata": {},
   "outputs": [],
   "source": [
    "mu1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b5cd8772-dd4d-486f-b39b-3581ba46db3e",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=(x-mu0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1db85bcc-e851-4ff5-bf74-4291048a850a",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bf90c0fe-f9e3-4187-9d28-6490a9dbc1b0",
   "metadata": {},
   "outputs": [],
   "source": [
    "final=(x-mu1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b66acfd5-c5b8-4284-bc5f-7f45b2ed66c5",
   "metadata": {},
   "outputs": [],
   "source": [
    "final"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e45a7294-4007-407a-b017-02d45134d7e1",
   "metadata": {},
   "source": [
    "$\\delta=x-\\mu_0,\\mu_1=\\mu_0+\\mu$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "85a50b2a-cadf-471d-8544-f64ff589f343",
   "metadata": {},
   "outputs": [],
   "source": [
    "final.subs({mu1:mu0+mu}).subs(x-mu0,delta)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dbbb678f-2625-4192-93a7-2044f5409a0d",
   "metadata": {},
   "outputs": [],
   "source": [
    "(3240-44**2-28**2)/S(8)-64"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cbeae192-1ac1-4291-8de2-6ec73b251ba4",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=exp(-1/x)-exp(1)*(x+2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01df5c65-43dd-4ddb-9c9b-0bbf9ff99a98",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "feebaab3-2dab-4f8f-a1bf-15765f29f819",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2ab60f00-1370-4f8c-a5c7-edda9993fae0",
   "metadata": {},
   "outputs": [],
   "source": [
    "fraction(_)[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bca58481-74c9-440b-be7f-9fdff4640c79",
   "metadata": {},
   "outputs": [],
   "source": [
    "check=_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb8e0ede-7f14-4a1c-8b2e-0d4d7310b6c8",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(check,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "50cdae95-3ca8-43c1-bd6e-ea541397a290",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=(m*x-1/x)*(x-1/x)**7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7c56a4ec-13a5-464b-83a1-9a6aff341582",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "37f538cf-4583-45c4-81f8-dd1ad041828a",
   "metadata": {},
   "outputs": [],
   "source": [
    "expand(expr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d1693e53-68e6-4cb6-8113-2fc217fc821f",
   "metadata": {},
   "outputs": [],
   "source": [
    "collect(_,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1a5ea9b2-0cb5-4498-8519-232b23557fba",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "binomial(7,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ff24fbb6-ac32-48de-a7cd-bdeeda448b35",
   "metadata": {},
   "outputs": [],
   "source": [
    "S(0.12)*S(0.56)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "05373d90-d93a-4aaa-add3-c2f6c4af2963",
   "metadata": {},
   "outputs": [],
   "source": [
    "S(0.084)*S(0.7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0a297a2e-ad7e-4dcd-aff8-c23fba927367",
   "metadata": {},
   "outputs": [],
   "source": [
    "A=Point(-1,2/sqrt(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ae888dda-91ca-4d11-bd17-ff98bd5a20f9",
   "metadata": {},
   "outputs": [],
   "source": [
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "90189495-f9b5-4c37-9fde-8e16677367b7",
   "metadata": {},
   "outputs": [],
   "source": [
    "B=-A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a7e2fb0e-27d2-4052-9c6d-6bdd3823e77e",
   "metadata": {},
   "outputs": [],
   "source": [
    "B"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "848cf3a0-7b78-4bc7-93b5-0a004c6788e9",
   "metadata": {},
   "outputs": [],
   "source": [
    "P=Point(x,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "515dc4d5-e8e5-495c-b181-dc47a28854ea",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq=Eq(-1/S(5),Line(A,P).slope*Line(B,P).slope)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2735113e-9139-4639-b695-4b836a9f529f",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dce6a1d5-6f5f-4396-bf2c-8b2bc54493d5",
   "metadata": {},
   "outputs": [],
   "source": [
    "equation_transfer(eq,fraction=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e32cf666-95f9-4041-869e-28e74f1a126f",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a5ed0299-701c-4e3a-b157-b21fbb9d1860",
   "metadata": {},
   "outputs": [],
   "source": [
    "M,=Intersection(Line(A,P),Line(x-3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a404f403-c022-4ec9-9ac3-a79eaa2274c2",
   "metadata": {},
   "outputs": [],
   "source": [
    "M"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1c2c78c9-7590-49a8-85de-225bc9d920ce",
   "metadata": {},
   "outputs": [],
   "source": [
    "N,=Intersection(Line(B,P),Line(x-3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ba455b93-067e-4c4a-95ea-c61d79e770eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "N"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "12996497-3e5a-4767-afbb-01bcd5f6a90c",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(N.distance(M))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0efa7f50-c834-42d0-ae9a-e472a2334782",
   "metadata": {},
   "outputs": [],
   "source": [
    "Triangle(M,N,P).area"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "869d4651-c931-40ef-b107-cee3974abfde",
   "metadata": {},
   "outputs": [],
   "source": [
    "Triangle(A,B,P).area"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a058eb52-4e80-4041-9495-fb4616604608",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq1=Eq(Triangle(M,N,P).area,Triangle(A,B,P).area)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9d2f1895-a74e-4bbb-9bc3-eeb02e90f795",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f660fa3c-43d3-4a68-8660-7e1eadbb5dbd",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq_area=simplify(equation_transfer(eq1,fraction=True,expr=True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "79a2b08d-d0fc-464f-a662-aefde123f689",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(eq_area)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "26a418bc-28ed-40dd-8032-c811658927d7",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq_slope=simplify(equation_transfer(eq,fraction=True,expr=True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e91915af-e95f-4489-8d41-a124bec20575",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq_slope"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "064b2c6a-c086-46ed-a5b3-2cb3ce63919d",
   "metadata": {},
   "outputs": [],
   "source": [
    "nonlinsolve([2*x+sqrt(5)*y,eq_slope],[x,y])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d95ade59-454e-4a8b-9c67-9eb15258e4a8",
   "metadata": {},
   "outputs": [],
   "source": [
    "nonlinsolve([x-S(5)/3,eq_slope],[x,y])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "16c37e0e-b483-4063-94e1-6a1491bcb6b3",
   "metadata": {},
   "outputs": [],
   "source": [
    "nonlinsolve([x**2+y**2-x*y-4,4*y**2+x**2+2*x*y-16],[x,y]) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f444c890-4b97-4672-918a-b3430859bcc5",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "chi=ChiSquaredTest(Matrix([[150,90],[60,100]]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aab388e4-ccc3-4d1c-b6bd-96ced457859f",
   "metadata": {},
   "outputs": [],
   "source": [
    "chi.expand_matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b2533e94-c3f0-4bf5-965f-e1f48483a932",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "chi.chi_squared_value"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1b96ee0e-52e5-447d-8d9b-6c573b7657f9",
   "metadata": {},
   "outputs": [],
   "source": [
    "N(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2c829eb6-58b7-4bef-8ef3-5397ee6286a9",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy import N"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "85e1633d-aae7-4bd9-a0df-ed9f045cd2cb",
   "metadata": {},
   "outputs": [],
   "source": [
    "N(chi.error_probability)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "67be8e14-e01f-4156-b458-baf561438e6a",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "chi_squared_of_error_probability(0.01)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d8ea9ff-a62e-459e-8910-6203d895699d",
   "metadata": {},
   "outputs": [],
   "source": [
    "for a in [0.5,0.25,0.1,0.05,0.01]:\n",
    "    print(N(chi_squared_of_error_probability(a)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b33000cb-cd5c-41bd-8301-f7bb50680b81",
   "metadata": {},
   "outputs": [],
   "source": [
    "from copy import deepcopy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "002cdf75-4d2d-4aba-a779-0669cb38ca85",
   "metadata": {},
   "outputs": [],
   "source": [
    "def binomial_result(v:list,n:int):\n",
    "    if n<=0:\n",
    "        return None\n",
    "    answer=[]\n",
    "    if n>=1:\n",
    "        for item in v:\n",
    "            answer.append([item])\n",
    "    \n",
    "    for i in range(n-1):\n",
    "        temp=deepcopy(answer)\n",
    "        answer=[]\n",
    "        for j in temp:\n",
    "            for item in v:\n",
    "                answer.append([*j,item])  \n",
    "    return answer\n",
    "            \n",
    "        \n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "304b170c-cbec-449e-a648-be94fbc4a539",
   "metadata": {},
   "outputs": [],
   "source": [
    "binomial_result([1,0],3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c65a15ca-e882-40db-9d63-90fa8ed52237",
   "metadata": {},
   "outputs": [],
   "source": [
    "def result_density(result:list):\n",
    "    density={}\n",
    "    for one in result:\n",
    "        # 获取单个结果的得分和概率\n",
    "        core=0\n",
    "        p=1\n",
    "        for i in range(len(one)):\n",
    "            # 特殊处理\n",
    "            if(i<=len(one)-2 and one[i:i+2]==[0,0]):\n",
    "                core-=1\n",
    "            # 一般性处理\n",
    "            if(one[i]==1):\n",
    "                core+=1\n",
    "                p*=S(2)/3\n",
    "            if(one[i]==0):\n",
    "                p*=S(1)/3\n",
    "        if(density.get(core)==None):\n",
    "            density[core]=p\n",
    "        else:\n",
    "            density[core]=density[core]+p\n",
    "    return density\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cfed136d-8774-40f0-865a-8a674fda196a",
   "metadata": {},
   "outputs": [],
   "source": [
    "result_density(binomial_result([1,0],3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c4bf6732-6255-4a12-bf0a-b0f2f6ea75a9",
   "metadata": {},
   "outputs": [],
   "source": [
    "answer=_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b12eb0bc-7a93-47e1-9e9e-8e0b521d842e",
   "metadata": {},
   "outputs": [],
   "source": [
    "X=FiniteRV(\"X\",answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "831c5a80-8593-45f5-a418-74126e3bfa0c",
   "metadata": {},
   "outputs": [],
   "source": [
    "E(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "32b43137-fd6a-45af-be16-2865167dc88f",
   "metadata": {},
   "outputs": [],
   "source": [
    "A=MatrixSymbol(\"A\",1,n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "23d5a20b-374c-4ab3-8772-c621ebdbbfc7",
   "metadata": {},
   "outputs": [],
   "source": [
    "A.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ae37b68-c5a7-4c94-806a-6bb6eb756992",
   "metadata": {},
   "outputs": [],
   "source": [
    "help(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f1e64dd6-3354-4982-812f-c743a3f5040b",
   "metadata": {},
   "outputs": [],
   "source": [
    "A=Matrix([[1,2,3]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a4187fb1-dec8-48b3-8854-eef69aa1c336",
   "metadata": {},
   "outputs": [],
   "source": [
    "type(A)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b7d48052-0b0f-4a23-8255-963675588d82",
   "metadata": {},
   "outputs": [],
   "source": [
    "def vecs_angle(vec1, vec2):\n",
    "    length_vec1 = sqrt(vec1.dot(vec1))\n",
    "    length_vec2 = sqrt(vec2.dot(vec2))\n",
    "    dot_time = vec1.dot(vec2)\n",
    "    return acos(dot_time / (length_vec1 * length_vec2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "636e3912-6dac-48bf-b32d-fb9a45494aa6",
   "metadata": {},
   "outputs": [],
   "source": [
    "B=Matrix([3,0,sqrt(3)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a64f1daa-4efa-4d54-a0e5-facca1bb4953",
   "metadata": {},
   "outputs": [],
   "source": [
    "B"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2ee17bff-d885-48ed-b0f9-e678c85241de",
   "metadata": {},
   "outputs": [],
   "source": [
    "C=Matrix([1/sqrt(3),1/sqrt(3),1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "37004d34-eaab-4d43-b7e3-8286b1279df4",
   "metadata": {},
   "outputs": [],
   "source": [
    "C"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0dd59b6e-7d2f-4038-a646-6b85c80de723",
   "metadata": {},
   "outputs": [],
   "source": [
    "vecs_angle(B,C)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c84e63c1-4c28-438c-b72a-8d46bda32410",
   "metadata": {},
   "outputs": [],
   "source": [
    "cos(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "46acb2d8-0cda-42c3-9e99-a6b82e96c773",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=2*f(n)-4*f(n-1)-(3*n**2-5*n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "743f20a5-29d5-4465-8e10-acfeab690533",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "de1e349b-b44c-4175-b7ec-c19acd831772",
   "metadata": {},
   "outputs": [],
   "source": [
    "rsolve(expr,f(n),{f(1):-1})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "699f4a52-20e8-4b6c-a7b8-4e23a44e858d",
   "metadata": {},
   "outputs": [],
   "source": [
    "sn=_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd9ff108-b295-4528-9947-51ce71334edd",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(sn-sn.subs(n,n-1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13ca24e5-05c0-479e-9e73-d078c3853262",
   "metadata": {},
   "outputs": [],
   "source": [
    "an=sequence(_,(n,1,oo))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "29727458-4d2f-44ea-974f-e40daa2ab712",
   "metadata": {},
   "outputs": [],
   "source": [
    "an"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f670ac8a-6b67-4fad-983c-76bca42fcf02",
   "metadata": {},
   "outputs": [],
   "source": [
    "sn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "20042e22-6fc7-474c-ac09-2d9b2e57258d",
   "metadata": {},
   "outputs": [],
   "source": [
    "bn=2**(n+1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "afb0099a-86df-418c-9d94-17a361a70156",
   "metadata": {},
   "outputs": [],
   "source": [
    "bn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3bd6cd0e-16f8-4b69-96d6-4d9240107def",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr_k=sn/bn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d4f191ae-c359-4070-97d1-537c3acf46a8",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(expand(expr_k))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b7ad2fe8-a2c9-40db-b112-e949875abda1",
   "metadata": {},
   "outputs": [],
   "source": [
    "function_range(simplify(expand(expr_k)),n,Interval(0,oo))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "afc521a7-b272-4d85-b060-f17d2b9834ed",
   "metadata": {},
   "outputs": [],
   "source": [
    "plot(simplify(expand(expr_k)),(n,0,5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb8982c0-d2e8-4f68-b3e6-40880e4c3c27",
   "metadata": {},
   "outputs": [],
   "source": [
    "sn.subs(n,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "87326093-350d-48ab-8ad9-10976787bb02",
   "metadata": {},
   "outputs": [],
   "source": [
    "(2-expand_power_exp(expand(expr_k)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b9687662-3901-4e1b-b00c-ec457a6eebbe",
   "metadata": {},
   "outputs": [],
   "source": [
    "cn=_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "471148e7-8259-4c09-9318-3a5ebc24cb81",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(cn.subs(n,n+1)-cn)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a62f027b-f12b-453f-b9d6-a06f2f4206f8",
   "metadata": {},
   "outputs": [],
   "source": [
    "cn.subs(n,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b8379328-dadb-495e-8fcf-6df1e437b322",
   "metadata": {},
   "outputs": [],
   "source": [
    "a,b=symbols(\"a,b\",positive=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "de80a942-616b-4997-9b84-76aa95de070f",
   "metadata": {},
   "outputs": [],
   "source": [
    "P=Point(a,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4f0c2497-9ef2-412b-a64b-33c91fbf019e",
   "metadata": {},
   "outputs": [],
   "source": [
    "l=Line(P,slope=-sqrt(3)/2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b364ed33-9dff-431e-bf48-09b647eedec5",
   "metadata": {},
   "outputs": [],
   "source": [
    "l.equation(x,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1ddca6b0-70fa-41d3-a497-ed0acac1a92f",
   "metadata": {},
   "outputs": [],
   "source": [
    "_.subs(x,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b2aebcee-07aa-4c94-b598-4778972ee56d",
   "metadata": {},
   "outputs": [],
   "source": [
    "Point(0,0).distance(l)-2*sqrt(21)/7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3875a9e2-cdec-4434-be81-140f43155478",
   "metadata": {},
   "outputs": [],
   "source": [
    "e=Ellipse(Point(0,0),2,sqrt(3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d5c92f23-7e90-4b17-b24a-34ac13067baa",
   "metadata": {},
   "outputs": [],
   "source": [
    "e.equation()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6e75af98-213b-46c7-be79-71c74ae78eb2",
   "metadata": {},
   "outputs": [],
   "source": [
    "x1,x2=symbols(\"x1:3\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ba43e5b6-d538-4e75-a5c4-79e0066c416b",
   "metadata": {},
   "outputs": [],
   "source": [
    "y1,y2=symbols(\"y1:3\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "75b59222-6c14-4109-af33-a75995841b89",
   "metadata": {},
   "outputs": [],
   "source": [
    "A=Point(x1,y1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8febad02-c463-4e4f-9e8d-dca086e7219d",
   "metadata": {},
   "outputs": [],
   "source": [
    "P=Point(2,0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "906e031c-6651-432f-b741-1e7bd56e4475",
   "metadata": {},
   "outputs": [],
   "source": [
    "B=Point(x2,y2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7321cab0-9484-4655-b048-722fcffdb7b9",
   "metadata": {},
   "outputs": [],
   "source": [
    "t=Line(A,P).slope*Line(B,P).slope"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13535849-7e68-4f26-aa4f-d4fb6146c759",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq=Eq(t,-3/S(4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b25846a7-b431-4a1d-9c6d-a05116cfbd1a",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e399ae5b-8b01-447a-ae11-238300653a3e",
   "metadata": {},
   "outputs": [],
   "source": [
    "eq.subs(y1*y2,-sqrt(3 - 3*x1**2/4)*sqrt(3 - 3*x2**2/4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d6aeb610-c11c-4be2-afdb-912787f857c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "equation_transfer(_,fraction=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "02c5c491-3621-4893-89f9-c1204f7bf50a",
   "metadata": {},
   "outputs": [],
   "source": [
    "equation_transfer(_,square=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a066a68-47a1-4a46-8efa-d48a29d407c8",
   "metadata": {},
   "outputs": [],
   "source": [
    "equation_transfer(_,expr=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8352019a-e989-4396-8799-00bca2557335",
   "metadata": {},
   "outputs": [],
   "source": [
    "check=simplify(expand(_))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "462dda47-f401-4e6b-947e-251bb39222ac",
   "metadata": {},
   "outputs": [],
   "source": [
    "check"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6d5b00a9-f5c9-4677-8063-29845698aa46",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(check)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7e7ef4bf-3180-4d16-995e-dd695bc5cbe7",
   "metadata": {},
   "outputs": [],
   "source": [
    "equation_transfer(eq,fraction=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4d72a309-3011-4437-b8db-b14e0581f13a",
   "metadata": {},
   "outputs": [],
   "source": [
    "expand(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ac78799f-3cb6-4530-b225-36e0f7b079fc",
   "metadata": {},
   "outputs": [],
   "source": [
    "data={y1*y2:list(solveset(eq,y1*y2))[0]}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "44ffb41f-e1cc-43dd-8ab6-0c5347f53b73",
   "metadata": {},
   "outputs": [],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d289f085-342d-4383-9fcc-b436bbc46a8e",
   "metadata": {},
   "outputs": [],
   "source": [
    "lengths=(A.distance(B))**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "11e85875-f83d-4e81-9523-5e8c1e3c951c",
   "metadata": {},
   "outputs": [],
   "source": [
    "data[y1**2]=list(solveset(e.equation(x,y).subs({y:y1,x:x1}),y1**2))[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a6bba6bb-e80b-4b05-ac18-ee2f952cd702",
   "metadata": {},
   "outputs": [],
   "source": [
    "data[y2**2]=list(solveset(e.equation(x,y).subs({y:y2,x:x2}),y2**2))[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd19861b-10ea-4249-80fd-51e3d40ae5ce",
   "metadata": {},
   "outputs": [],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d27a726d-c671-4659-a5af-2911f9251f8f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "52c8f43d-de42-4b06-9c30-b5dba8ef2113",
   "metadata": {},
   "outputs": [],
   "source": [
    "expand(lengths).subs(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "656ad174-76b1-4691-88f0-871e47c96c86",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8bc1dab4-5546-412e-ae37-b180aed8ca42",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d7f26b04-cb79-42c9-9e4a-ce464788c19b",
   "metadata": {},
   "outputs": [],
   "source": [
    "k1,k2=symbols(\"k1:3\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a53a1286-42fe-4562-84bb-62b8a3f9fbd7",
   "metadata": {},
   "outputs": [],
   "source": [
    "l1=Line(y-k1*(x-2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47b9e6f8-88c6-4caa-8e37-3a9e3c891990",
   "metadata": {},
   "outputs": [],
   "source": [
    "line_and_quadratic(l1,e,x=x,y=y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3dbabdcc-3384-403f-9354-10d14ef210c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "solveset(_,x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e39bc503-0cc6-4315-96cd-125b4cc6d7af",
   "metadata": {},
   "outputs": [],
   "source": [
    "check=list(_)[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cce84995-92cd-45cc-b263-18adb4f8e4b9",
   "metadata": {},
   "outputs": [],
   "source": [
    "check.subs(k1,-3/(4*k2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7780aa93-7c85-45f2-8252-6228d73b621d",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e5aaf7b7-8371-41b3-b118-e781b5fc990b",
   "metadata": {},
   "outputs": [],
   "source": [
    "answer=list(solveset(l1.equation(x,y).subs(x,check),y))[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2ba4bce5-20a9-4c9a-a56d-8e02b1fbdae7",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(answer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ae30fdc4-b2e8-4f42-8af2-924ecc34a01d",
   "metadata": {},
   "outputs": [],
   "source": [
    "_.subs(k1,-3/(4*k2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bdbfacd4-a764-44e4-81c5-ec78ed262baf",
   "metadata": {},
   "outputs": [],
   "source": [
    "simplify(_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6f5be1d0-68df-47e1-bec8-c6e69201ce69",
   "metadata": {},
   "outputs": [],
   "source": [
    "a=symbols(\"a\",real=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c80c86a-b567-44db-876a-a435f34f90d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=(exp(x)-a)/(x+1)-a*ln(x+1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "84f905b3-ede6-4ff6-ae18-6b04c4d36730",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "382eee20-740b-4a2a-80ac-a73f8823a42d",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b67ef796-2c62-4f96-8657-898fd14a928e",
   "metadata": {},
   "outputs": [],
   "source": [
    "N(log(2,10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "de366f84-85a9-4c77-8d89-13dc8e73e7c8",
   "metadata": {},
   "outputs": [],
   "source": [
    "N(log(3,10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d9e79b7b-d3ee-46d2-a9ef-42fe292930ea",
   "metadata": {},
   "outputs": [],
   "source": [
    "5730*15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1e75d7bc-1acc-47d2-aa1e-e93a43611e09",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr=(x+1)/(x-1)*ln(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "650d7bad-91df-4d7e-90a1-37d2bb137282",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "function_range(expr,x,Interval.open(1,oo))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5c1ded21-b808-4536-b512-df70803f56ee",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr,x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4b3716c0-8ea3-41cd-a646-63cb6edbaa11",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr_1=fraction(_)[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "34e91c4b-670e-4540-ae2e-1418a24f084f",
   "metadata": {},
   "outputs": [],
   "source": [
    "expr_1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9a1a36e4-831f-475f-ac90-ba0189257c14",
   "metadata": {},
   "outputs": [],
   "source": [
    "factor(diff(expr_1))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
